
#include <stdio.h>
#include "dalvik.h"
#include "dalvik-opcode.h"

extern unsigned insn_len_of_fmt[]={

0,//fmt_00x,
1,//fmt_10x,
1,//fmt_12x,
1,//fmt_11n,
1,//fmt_11x,
1,//fmt_10t,
2,//fmt_20t,
2,//fmt_20bc,
2,//fmt_22x,
2,//fmt_21t,
2,//fmt_21s,
2,//fmt_21h,
2,//fmt_21c,
2,//fmt_23x,
2,//fmt_22b,
2,//fmt_22t,
2,//fmt_22s,
2,//fmt_22c,
2,//fmt_22cs,
3,//fmt_30t,
3,//fmt_32x,
3,//fmt_31i,
3,//fmt_31t,
3,//fmt_31c,
3,//fmt_35c,
3,//fmt_35ms,
3,//fmt_35mi,
3,//fmt_3rc,
3,//fmt_3rms,
3,//fmt_3rmi,
5,//fmt_51l,

};

void print_fmt(PINSN_INFO p_insn_info)
{

	switch(p_insn_info->fmt)
	{
	case fmt_00x:
	{
		INSN_INFMT_00x * p_insn=(INSN_INFMT_00x *)p_insn_info->code;
			printf("N/A");
	}
	break;
	case fmt_10x:
	{
		INSN_INFMT_10x * p_insn=(INSN_INFMT_10x *)p_insn_info->code;
		printf("%s",p_insn->op);
	}
	break;
	case fmt_12x:
	{
		INSN_INFMT_12x * p_insn=(INSN_INFMT_12x *)p_insn_info->code;
		printf("%s v%s, v%s",p_insn->op,p_insn->A,p_insn->B);
	}
	break;
	case fmt_11n:
	{
		INSN_INFMT_11n * p_insn=(INSN_INFMT_11n *)p_insn_info->code;
		printf("%s v%s, #+B",p_insn->op,p_insn->A,p_insn->B);
	}
	break;
	case fmt_11x:
	{
		INSN_INFMT_11x * p_insn=(INSN_INFMT_11x *)p_insn_info->code;
		printf("%s v%s",p_insn->op,p_insn->AA);
	}
	break;
	case fmt_10t:
	{
		INSN_INFMT_10t * p_insn=(INSN_INFMT_10t *)p_insn_info->code;
		printf("%s +AA",p_insn->op,p_insn->AA);
	}
	break;
	case fmt_20t:
	{
		INSN_INFMT_20t * p_insn=(INSN_INFMT_20t *)p_insn_info->code;
		printf("%s +%s",p_insn->op,p_insn->AAAA);
	}
	break;
	case fmt_20bc:
	{
		INSN_INFMT_20bc * p_insn=(INSN_INFMT_20bc *)p_insn_info->code;
		printf("%s AA, kind@%s",p_insn->op,p_insn->BBBB);
	}
	break;
	case fmt_22x:
	{
		INSN_INFMT_22x * p_insn=(INSN_INFMT_22x *)p_insn_info->code;
		printf("%s v%s, v%s",p_insn->op,p_insn->AA,p_insn->BBBB);
	}
	break;
	case fmt_21t:
	{
		INSN_INFMT_21t * p_insn=(INSN_INFMT_21t *)p_insn_info->code;
		printf("%s v%s, +%s",p_insn->op,p_insn->AA,p_insn->BBBB);
	}
	break;
	case fmt_21s:
	{
		INSN_INFMT_21s * p_insn=(INSN_INFMT_21s *)p_insn_info->code;
		printf("%s v%s, #+%s",p_insn->op,p_insn->AA,p_insn->BBBB);
	}
	break;
	case fmt_21h:
	{
		INSN_INFMT_21h * p_insn=(INSN_INFMT_21h *)p_insn_info->code;
		printf("%s v%s, #+%s0000",p_insn->op,p_insn->AA,p_insn->BBBB);
		printf("%s v%s, #+%s000000000000",p_insn->op,p_insn->AA,p_insn->BBBB);
	}
	break;
	case fmt_21c:
	{
		INSN_INFMT_21c * p_insn=(INSN_INFMT_21c *)p_insn_info->code;
		printf("%s v%s, type@%s",p_insn->op,p_insn->AA,p_insn->BBBB);
		printf("%s v%s, field@%s",p_insn->op,p_insn->AA,p_insn->BBBB);
		printf("%s v%s, string@%s",p_insn->op,p_insn->AA,p_insn->BBBB);
	}
	break;
	case fmt_23x:
	{
		INSN_INFMT_23x * p_insn=(INSN_INFMT_23x *)p_insn_info->code;
		printf("%s v%s, v%s, v%s",p_insn->op,p_insn->AA,p_insn->BB,p_insn->CC);
	}
	break;
	case fmt_22b:
	{
		INSN_INFMT_22b * p_insn=(INSN_INFMT_22b *)p_insn_info->code;
		printf("%s v%s, v%s, #+CC",p_insn->op,p_insn->AA,p_insn->BB,p_insn->CC);
	}
	break;
	case fmt_22t:
	{
		INSN_INFMT_22t * p_insn=(INSN_INFMT_22t *)p_insn_info->code;
		printf("%s v%s, v%s, +CCCC",p_insn->op,p_insn->A,p_insn->B,p_insn->CCCC);
	}
	break;
	case fmt_22s:
	{
		INSN_INFMT_22s * p_insn=(INSN_INFMT_22s *)p_insn_info->code;
		printf("%s v%s, v%s, #+CCCC",p_insn->op,p_insn->A,p_insn->B,p_insn->CCCC);
	}
	break;
	case fmt_22c:
	{
		INSN_INFMT_22c * p_insn=(INSN_INFMT_22c *)p_insn_info->code;
		printf("%s v%s, v%s, type@CCCC",p_insn->op,p_insn->A,p_insn->B,p_insn->CCCC);
		printf("%s v%s, v%s, field@CCCC",p_insn->op,p_insn->A,p_insn->B,p_insn->CCCC);
	}
	break;
	case fmt_22cs:
	{
		INSN_INFMT_22cs * p_insn=(INSN_INFMT_22cs *)p_insn_info->code;
		printf("%s v%s, v%s, fieldoff@CCCC",p_insn->op,p_insn->A,p_insn->B,p_insn->CCCC);
	}
	break;
	case fmt_30t:
	{
		INSN_INFMT_30t * p_insn=(INSN_INFMT_30t *)p_insn_info->code;
		printf("%s +%s%s",p_insn->op,p_insn->AAAAlo,p_insn->AAAAhi);
	}
	break;
	case fmt_32x:
	{
		INSN_INFMT_32x * p_insn=(INSN_INFMT_32x *)p_insn_info->code;
		printf("%s v%s, v%s",p_insn->op,p_insn->AAAA,p_insn->BBBB);
	}
	break;
	case fmt_31i:
	{
		INSN_INFMT_31i * p_insn=(INSN_INFMT_31i *)p_insn_info->code;
		printf("%s v%s, #+%s%s",p_insn->op,p_insn->AA,p_insn->BBBBlo,p_insn->BBBBhi);
	}
	break;
	case fmt_31t:
	{
		INSN_INFMT_31t * p_insn=(INSN_INFMT_31t *)p_insn_info->code;
		printf("%s v%s, +%s%s",p_insn->op,p_insn->AA,p_insn->BBBBlo,p_insn->BBBBhi);
	}
	break;
	case fmt_31c:
	{
		INSN_INFMT_31c * p_insn=(INSN_INFMT_31c *)p_insn_info->code;
		printf("%s v%s, string@%s%s",p_insn->op,p_insn->AA,p_insn->BBBBlo,p_insn->BBBBhi);
	}
	break;
	case fmt_35c:
	{
		INSN_INFMT_35c * p_insn=(INSN_INFMT_35c *)p_insn_info->code;
		if (p_insn->A==5){
			printf("%s { v%s, v%s, v%s, v%s, v%s }, meth@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->F,p_insn->G,p_insn->BBBB);
		}
		else if (p_insn->A==5){
			printf("%s { v%s, v%s, v%s, v%s, v%s }, type@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->F,p_insn->G,p_insn->BBBB);
		}
		else if (p_insn->A==4){
			printf("%s { v%s, v%s, v%s, v%s }, kind@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->F,p_insn->BBBB);
		}
		else if (p_insn->A==3){
			printf("%s { v%s, v%s, v%s }, kind@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->BBBB);
		}
		else if (p_insn->A==2){
			printf("%s { v%s, v%s }, kind@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->BBBB);
		}
		else if (p_insn->A==1){
			printf("%s { v%s }, kind@%s",p_insn->op,p_insn->C,p_insn->BBBB);
		}
		else if (p_insn->A==0){
			printf("%s { }, kind@%s",p_insn->op,p_insn->BBBB);
		}
	}
	break;
	case fmt_35ms:
	{
		INSN_INFMT_35ms * p_insn=(INSN_INFMT_35ms *)p_insn_info->code;
		if (p_insn->A==5){
			printf("%s { v%s, v%s, v%s, v%s, v%s }, vtaboff@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->F,p_insn->G,p_insn->BBBB);
		}
		else if (p_insn->A==4){
			printf("%s { v%s, v%s, v%s, v%s }, vtaboff@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->F,p_insn->BBBB);
		}
		else if (p_insn->A==3){
			printf("%s { v%s, v%s, v%s }, vtaboff@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->BBBB);
		}
		else if (p_insn->A==2){
			printf("%s { v%s, v%s }, vtaboff@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->BBBB);
		}
		else if (p_insn->A==1){
			printf("%s { v%s }, vtaboff@%s",p_insn->op,p_insn->C,p_insn->BBBB);
		}
	}
	break;
	case fmt_35mi:
	{
		INSN_INFMT_35mi * p_insn=(INSN_INFMT_35mi *)p_insn_info->code;
		if (p_insn->A==5){
			printf("%s { v%s, v%s, v%s, v%s, v%s }, inline@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->F,p_insn->G,p_insn->BBBB);
		}
		else if (p_insn->A==4){
			printf("%s { v%s, v%s, v%s, v%s }, inline@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->F,p_insn->BBBB);
		}
		else if (p_insn->A==3){
			printf("%s { v%s, v%s, v%s }, inline@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->E,p_insn->BBBB);
		}
		else if (p_insn->A==2){
			printf("%s { v%s, v%s }, inline@%s",p_insn->op,p_insn->C,p_insn->D,p_insn->BBBB);
		}
		else if (p_insn->A==1){
			printf("%s { v%s }, inline@%s",p_insn->op,p_insn->C,p_insn->BBBB);
		}
	}
	break;
	case fmt_3rc:
	{
		INSN_INFMT_3rc * p_insn=(INSN_INFMT_3rc *)p_insn_info->code;
		printf("%s { v%s .. v%s }, meth@%s",p_insn->op,p_insn->CCCC,p_insn->CCCC+p_insn->AA-1,p_insn->BBBB);
		printf("%s { v%s .. v%s }, type@%s",p_insn->op,p_insn->CCCC,p_insn->CCCC+p_insn->AA-1,p_insn->BBBB);
	}
	break;
	case fmt_3rms:
	{
		INSN_INFMT_3rms * p_insn=(INSN_INFMT_3rms *)p_insn_info->code;
		printf("%s { v%s .. v%s }, vtaboff@%s",p_insn->op,p_insn->CCCC,p_insn->CCCC+p_insn->AA-1,p_insn->BBBB);
	}
	break;
	case fmt_3rmi:
	{
		INSN_INFMT_3rmi * p_insn=(INSN_INFMT_3rmi *)p_insn_info->code;
		printf("%s { v%s .. v%s }, inline@%s",p_insn->op,p_insn->CCCC,p_insn->CCCC+p_insn->AA-1,p_insn->BBBB);
	}
	break;
	case fmt_51l:
	{
		INSN_INFMT_51l * p_insn=(INSN_INFMT_51l *)p_insn_info->code;
		printf("%s v%s, #+%s%s%s%s",p_insn->op,p_insn->AA,p_insn->BBBBlo,p_insn->BBBBmilo,p_insn->BBBBmihi,p_insn->BBBBhi);
	}
	break;

   }
}

